package cn.bingoo.nginx;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import cn.bingoo.swing.utils.Dbs;

public class NginxDbUtils {
    public static Connection getConnectionWithTableAutoCreate() throws SQLException {
        Connection conn;
        DriverManager.registerDriver(new org.h2.Driver());
        conn = DriverManager.getConnection("jdbc:h2:~/bingoo-handy", "sa", "");
        if (!Dbs.tableExists(conn, "NGINXSTATUS")) {
            String ddl = "CREATE TABLE NGINXSTATUS (URL VARCHAR(100) NOT NULL, Ts TIMESTAMP, ACTIVES Integer NOT NULL, ACCEPTS Integer, HANDLED Integer, REQUESTS Integer, READING Integer, WRITING Integer, WAITING Integer, PRIMARY KEY (URL,Ts))";
            Dbs.execute(conn, ddl);
        }
        return conn;
    }
}
